local ma__fenyong = fk.CreateSkill{
  name = "ma__fenyong"
}

Fk:loadTranslationTable{
  ["ma__fenyong"] = "奋勇",
  [":ma__fenyong"] = "当你回复体力后，你下回合开始时选择一项：<br>"..
    "1.摸X张牌；2.对一名体力值不小于你的角色造成X点伤害（X为回复的体力值）。",

  ["#ma__fenyong"] = "奋勇：对一名角色造成%arg点伤害（或点击取消摸牌）",
  ["@ma__fenyong"] = "奋勇",

  ["$ma__fenyong1"] = "吾等十万军，岂会败你八百众！",
  ["$ma__fenyong2"] = "江东尽铁血男儿，可死不可退也！",
}

ma__fenyong:addEffect(fk.TurnStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ma__fenyong.name) and
      player:getMark("@ma__fenyong") > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = player:getMark("@ma__fenyong")
    room:removePlayerMark(player, "@ma__fenyong", n)
    local targets = table.filter(room.alive_players, function (p)
      return p.hp >= player.hp and p ~= player
    end)
    local to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#ma__fenyong:::"..n,
      skill_name = ma__fenyong.name,
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to, num = n})
      return true
    else event:setCostData(self, {tos = nil, num = n})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = event:getCostData(self).num
    if event:getCostData(self).tos ~= nil then
      local to = event:getCostData(self).tos[1]
      room:damage({
        from = player,
        to = to,
        damage = n,
        skillName = ma__fenyong.name,
      })
    else player:drawCards(n, ma__fenyong.name)
    end
  end,
})

ma__fenyong:addEffect(fk.HpRecover, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(ma__fenyong.name)
  end,
  on_use = function (self, event, target, player, data)
    local n = data.num
    player.room:addPlayerMark(player, "@ma__fenyong", n)
  end,
})

return ma__fenyong
